<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Web Workers</title>
</head>
<body>
  <input type="text" placeholder="请输入数字" id="input"><br/>
  <button id="button">计算</button>
  <script>
   let input = document.getElementById('input')
   document.getElementById('button').onclick = function() {
      let number = input.value

      let workers = new Worker('./workers.js')

      workers.onmessage = (event) => {
        console.log('主线接收分线程返回的数据：' + event.data)
      }

      workers.onerror = (event) => {
        console.log('onerror:' + event)
      } 

      workers.postMessage(number)
      console.log('主线程向分线程发送数据：'+number)

   
    }
  </script>
</body>
</html>